package try_java;

import java.util.Scanner;
public class InputTest {
    public static void main (String [] args) {
        int next = 1;
        Scanner in = new Scanner(System.in);
        String mode; 
        while (next == 1) {
            System.out.println("input the mode");
            if (in.hasNext()) {
                mode = in.next();
                System.out.println("mode is " + mode);
                in.nextLine();
                System.out.println("what is your name");
                
                if (mode.equals("line")) {
                    String name = in.nextLine();
                    System.out.println("this is line");
                    System.out.println("your name is " + name);
                }
                else {
                    if (mode.equals("word")) {
                        if (in.hasNext()) {
                            String name = in.next();
                            System.out.println("your name is " + name);
                        }
                        else {
                            System.err.println("You input wrong type, should input word only");
                        }
                        
                    }
                    else if (mode.equals("int")) {
                        if (in.hasNextInt()) {
                            int name = in.nextInt();
                            System.out.printf("your name is %d\n", name);
                        }
                        else {
                            System.err.println("You input wrong type, should input int only");
                        }
                        
                    }
                    else if (mode.equals("double")) {
                        if (in.hasNextDouble()) {
                            double name = in.nextDouble();
                            System.out.printf("your name is %f\n", name);
                        }
                        else {
                            System.err.println("You input wrong type, should input double only");
                        }
                        
                    }
                    if (in.hasNextLine()) {
                        System.out.println("has some thing");
                        String something = in.nextLine();
                        System.out.println("There is something*" + something + "*");
                    }
                }
            }
            else {
                System.err.println("You input wrong type, should input word only");
            }
            System.out.println("keep testing...?");
            if (in.hasNextInt()) {
                next = in.nextInt();
            }
            else {
                in.nextLine();
            }
            System.out.printf("next is %d \n", next);
            
        }
        System.out.println("test has finished");
        in.close();
        
        
    }
}
